$(document).ready(function(){
	bIslogin = false;
	bFnIsLogin(fnIsLoginCallback);
//	fnIsLogin();
	fnGetUploadList(fnRenderUploadList);
	fnGetCollectionList(fnRenderCollectionList);
	fnAddEvent();
	fnAddEventForUser();
	fnInitUpload();
});
function fnAddEventForUser(){
	$(document).on('click','.cancelCollect',function(){
		fnCancelCollect($(this));
	});
	$('.videoUpload').on('click',function(){
		if(bIslogin){
			oDialogHandle.fnShowUpload();
		}else{
			alert('请先登录');
		}
	});
	$('.confirm').on('click',function(e){
		fnConfirm($(this));
	});
	$('.cancel').on('click',function(e){
		oDialogHandle.fnRemoveAll();
	});
}
function bFnIsLogin(callback){
	$.ajax({
		url:'/api/login.php',
		type:'post',
		dataType:'json',
		data:{
			method:'isLogin'
		},
		success:function(data){
			callback(data);
		}
	});
}
function fnIsLoginCallback(data){
	var root = {list : data};
	if(data.loginStatus){
		bIslogin = true;
		var oRenderOption = {
			sTplId : 'tpl-personal',
			oData : root,
			sRenderType : 'html',
			oContainer : $('.header') 
		}
		fnRender(oRenderOption);
	}else{
		var oRenderOption = {
			sTplId : 'tpl-loginNav',
			oData : '',
			sRenderType : 'html',
			oContainer : $('.header')
		}
		fnRender(oRenderOption);
	}
}
function fnGetUploadList(callback){
	$.ajax({
		url:'/api/list.php',
		type:'post',
		dataType:'json',
		data:{
			method:'uploadList'
		},
		success:function(data){
			callback(data);
		}
	});
}
function fnGetCollectionList(callback){
	$.ajax({
		url:'/api/list.php',
		type:'post',
		dataType:'json',
		data:{
			method:'collectionList'
		},
		success:function(data){
			callback(data);
		}
	});
}
function fnRenderUploadList(data){
	console.log(data);
	var oRoot = {list : data};
	var oRenderOption = {
		sTplId:'tpl-uploadList',
		oData:oRoot,
		sType:'html',
		oContainer:$('.uploadList')
	}
	if(data !='fail'){
		fnRender(oRenderOption);		
	}
}
function fnRenderCollectionList(data){
	console.log(data);
	var oRoot = {list : data};
	var oRenderOption = {
		sTplId:'tpl-collectionList',
		oData:oRoot,
		sType:'html',
		oContainer:$('.collectionList')
	}
	if(data != 'fail'){
		fnRender(oRenderOption);	
	}
}
function fnCancelCollect(target){
	var videoId = target.attr('data-videoId');
	fnCollect(videoId);
}